#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution {
public:
    bool check(int* hash1, int* hash2)
    {
        for (int i = 0; i < 26; i++)
        {
            if (hash1[i] != hash2[i]) return false;
        }
        return true;
    }
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> v;
        int hash1[26] = { 0 }, hash2[26] = { 0 };
        int m = p.size();
        for (auto& x : p)
            hash1[x - 'a']++;
        for (int l = 0, r = 0; r < s.size(); r++)
        {
            hash2[s[r] - 'a']++;
            if (r - l + 1 > m)
                hash2[s[l++] - 'a']--;
            if (check(hash1, hash2)) v.emplace_back(l);
        }
        return v;
    }
};
int main()
{
    Solution s;
    s.findAnagrams("abab", "ab");
	return 0;
}